package com.guaju.yueshangLife.widget.mine;

import android.content.Context;
import android.content.res.TypedArray;
import android.databinding.DataBindingUtil;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import com.guaju.yueshangLife.R;
import com.guaju.yueshangLife.databinding.ItemMineCateBinding;

public class ItemMineCate extends FrameLayout {

    private ItemMineCateBinding binding;

    public ItemMineCate(Context context) {
        super(context);
        init();
    }

    public ItemMineCate(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.item_mine_cate);
        int resourceId = ta.getResourceId(R.styleable.item_mine_cate_cate_icon, 0);
        String string = ta.getString(R.styleable.item_mine_cate_cate_title);
        String nums = ta.getString(R.styleable.item_mine_cate_nums);
        binding.cateIcon.setBackgroundResource(resourceId);
        binding.cateTitle.setText(string);
        if (TextUtils.isEmpty(nums)) {
            binding.nums.setVisibility(View.GONE);
        } else {
            binding.nums.setVisibility(View.VISIBLE);
            binding.nums.setText(nums);
        }
    }

    private void init() {
        binding = DataBindingUtil.inflate(LayoutInflater.from(getContext()), R.layout.item_mine_cate, null, false);
        addView(binding.getRoot());
    }

    public void setNums(int num) {
        if (num > 0) {
            binding.nums.setVisibility(View.VISIBLE);
            binding.nums.setText(num + "");
        }
    }
    public void setText(String text){
        if (!TextUtils.isEmpty(text)){
        binding.cateTitle.setText(text);
        }
    }
}
